package com.ewanghuiju.app.ui.my.activity;

import android.view.Gravity;
import android.view.View;

import com.ewanghuiju.app.R;
import com.ewanghuiju.app.base.SimpleActivity;
import com.ewanghuiju.app.util.ClipboardUtils;
import com.ewanghuiju.app.util.PermissionUtil;
import com.ewanghuiju.app.util.PhoneUtils;
import com.ewanghuiju.app.util.ToastUtil;
import com.ewanghuiju.app.util.nodoubleclick.AntiShake;
import com.ewanghuiju.app.widget.popupwindow.CustomBasePopup;
import com.gyf.immersionbar.ImmersionBar;

import butterknife.OnClick;

/**
 * @author sj  qq:751943509
 * @class 客服中心
 * @time 2020/2/19
 */
public class KefuCenterActivity extends SimpleActivity {

    private CustomBasePopup customBasePopup;

    @Override
    protected int getLayout() {
        return R.layout.activity_kefu_center;
    }

    @Override
    protected void initEventAndData() {
    }

    @Override
    protected int getTitleIntText() {
        return R.string.kefu_center_title;
    }


    @OnClick({R.id.tv_zb_zj, R.id.tv_zb_sj, R.id.tv_fb_zj, R.id.tv_fb_sj, R.id.tv_email_content})
    public void doClick(View view) {
        if (AntiShake.check(view.getId())) {    //判断是否多次点击
            return;
        }
        switch (view.getId()) {
            case R.id.tv_zb_zj:
                //总部座机
//                callPhone("02180316484");
                showCallDialog("021-8031 6484");
                break;
            case R.id.tv_zb_sj:
                //总部手机
                showCallDialog("15356239444");
                break;
            case R.id.tv_fb_zj:
                //分部座机
                showCallDialog("0512--6808 6768");
                break;
            case R.id.tv_fb_sj:
                //分部手机
                callPhone("15356239444");
                break;
            case R.id.tv_email_content:
                //复制邮箱
                ClipboardUtils.copyText("ewanghuiju@163.com", "复制成功");
                break;
            default:
                break;
        }
    }

    public void showCallDialog(String teleNumber) {
        try {
//            if (customBasePopup != null) {
//                customBasePopup.setTitleText("是否拨打" + teleNumber + "？");
//                customBasePopup.showPopupWindow();
//                return;
//            }
            customBasePopup = new CustomBasePopup(mContext, "是否拨打" + teleNumber + "？", "", "",
                    new CustomBasePopup.PopupWindowCallback() {
                        @Override
                        public void sureClickCallback() {
                            callPhone(teleNumber);
                        }

                        @Override
                        public void cancelClickCallback() {

                        }
                    });
            customBasePopup.setPopupGravity(Gravity.CENTER);
            customBasePopup.showPopupWindow();

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /**
     * 拨打电话
     */
    public void callPhone(String phoneNumber) {
        PermissionUtil.requestPermissionForActivity(this, new PermissionUtil.IPermissionListener() {
            @Override
            public void permissionGranted() {
                PhoneUtils.call(phoneNumber);
            }

            @Override
            public void permissionDenied() {
                ToastUtil.show("权限被拒绝,请设置应用权限");
            }
        }, "权限被拒绝,请设置应用权限", PermissionUtil.call_phone_permissions);
    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this)
                .titleBar(mToolbar, true)
                .statusBarDarkFont(true)
                .init();
    }
}
